﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using BUS;
using DTO;

namespace DoAnHuongRung
{
    public partial class frmUpdateNghiPhep : Form
    {
        frmQuanLyNghiPhep parent = null;
        public frmUpdateNghiPhep(frmQuanLyNghiPhep MyParent)
        {
            InitializeComponent();

            parent = MyParent;
            lblNgay.Text = parent.dtgLichLamViec.CurrentRow.Cells[2].Value.ToString();
            lblCa.Text = parent.dtgLichLamViec.CurrentRow.Cells[3].Value.ToString();
            lblCa.Tag = parent.dtgLichLamViec.CurrentRow.Cells[4].Value.ToString();
        }

        private void frmUpdateNghiPhep_Load(object sender, EventArgs e)
        {
            LoadcmbNhanVien();
        }

        private void LoadcmbNhanVien()
        {
            int CaLamViec = int.Parse(lblCa.Tag.ToString());
            string Ngay = lblNgay.Text;
            cmbNhanVien.DisplayMember = "TenNhanVien";
            cmbNhanVien.ValueMember = "MaNhanVien";
            cmbNhanVien.DataSource = LichLamViecBUS.Select_NhanVien_not_exists_in_CaLamViec_Ngay(CaLamViec, Ngay);
        }

        private void btnLuu_Click(object sender, EventArgs e)
        {
            try
            {
                NghiPhepDTO np = new NghiPhepDTO();
                np.MaNhanVien = int.Parse(parent.dtgLichLamViec.CurrentRow.Cells[7].Value.ToString());
                np.NgayBatDauNghi = dateTimePicker1.Value.ToString("MM/dd/yyyy");
                np.SoNgayNghi = int.Parse(txtSoNgayNghi.Value.ToString());
                bool b = NghiPhepBUS.Insert(np);
                if (b == true)
                {
                    LichLamViecDTO llv = new LichLamViecDTO();
                    llv.MaLLV = int.Parse(parent.dtgLichLamViec.CurrentRow.Cells[0].Value.ToString());
                    llv.MaNhanVien = int.Parse(cmbNhanVien.SelectedValue.ToString());
                    b = LichLamViecBUS.Update(llv);
                    if (b == true)
                    {
                        MessageBox.Show("Nghỉ phép thành công !!!");
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
    }
}
